package br.com.ambgis.sicap;

import java.util.List;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class PlacaArrayAdapter extends ArrayAdapter<Placa> {

	@SuppressWarnings("unused")
	private final List<Placa> list;
	private final Activity context;

	public PlacaArrayAdapter(Activity context, List<Placa> list) {
		super(context, R.layout.placa_row, list);
		this.context = context;
		this.list = list;
	}

	static class ViewHolder {
		protected TextView text;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View row = convertView;
		if (row == null) {
			LayoutInflater inflator = context.getLayoutInflater();
			row = inflator.inflate(R.layout.placa_row, null);
			final ViewHolder viewHolder = new ViewHolder();
			viewHolder.text = (TextView) row.findViewById(R.id.placaName);
			row.setTag(viewHolder);
		}
		ViewHolder holder = (ViewHolder) row.getTag();
		Placa model = this.getItem(position);
		holder.text.setText(model.getDescricao());
		return row;
	}

	@Override
	public long getItemId(int position) {
		return getItem(position).getId();
	}
}